﻿/**
 * 生产计划相关Js代码
 * Dai 2022-12-20
 * **/

/**
 * 工序生产小组(下拉控件)
 * gxCode：工序编码
 * controlId:控件ID
 * defaultValue:默认值
 * **/
function GongXuGroup(gxCode, controlId, defaultValue,isEmp) {
    $.ajax({
        url: "../ProductSet/GetGongXuGroup",
        data: { gxCode: gxCode },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                $("#" + controlId).empty();
                if (isEmp) {
                    $("#" + controlId).append("<option value='' >选择班组</option>");
                }
                for (var i = 0; i < datas.length; i++) {

                    if (datas[i]["cCode"] != "") {
                        $("#" + controlId).append("<option value=\"" + datas[i]["cCode"] + "\" >" + datas[i]["cName"] + "(" + datas[i]["cCode"] + ")" + "</option>");
                    }

                }
                if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
} 

/**
   子工序
   **/
function ChildGongXu(gxCode, controlId, dValue, isEmp) {
    $.ajax({
        url: "../ProductSet/GetChildGongXu",
        type: "POST",
        data: { gxCode: gxCode },
        success: function (data) {
            if (data.Result) {
                var datas = data.Data;
                $("#" + controlId).empty();
                if (isEmp) {
                    $("#" + controlId).append("<option value='' >选择工序</option>");
                }
                for (var i = 0; i < datas.length; i++) {
                    $("#" + controlId).append("<option value=\"" + datas[i]["cgxCode"] + "\" >" + datas[i]["cgxName"] + "</option>");
                }
                if (dValue != undefined && dValue != "") {
                    $("#" + controlId +" option[value='" + dValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
}

/**
 * 货位(下拉控件)
 * wareCode：仓库编码
 * controlId:控件ID
 * defaultValue:默认值
 * **/
function warePosition(wareCode, controlId, defaultValue, isEmp) {
    $.ajax({
        url: "../Basis/GetDataList",
        data: { dataType: "wp", condition: wareCode },
        dataType: "json",
        type: "GET",
        async: false,
        success: function (data) {
            if (data.msg=="") {
                var datas = data.data;
                $("#" + controlId).empty();
                if (isEmp) {
                    $("#" + controlId).append("<option value='' >选择货位</option>");
                }
                for (var i = 0; i < datas.length; i++) {
                    
                    if (datas[i]["cCode"] != "") {
                        $("#" + controlId).append("<option value=\"" + datas[i]["cCode"] + "\" >" + datas[i]["cName"] + "(" + datas[i]["cCode"] + ")" + "</option>");
                    }

                }
                if (defaultValue != undefined && defaultValue != "") {
                    $("#" + controlId + " option[value='" + defaultValue + "'] ").attr("selected", true);
                }
                layui.use('form', function () {
                    var form = layui.form;
                    form.render();
                });
            }
        }
    });
}
